package example.strategy.symmetry;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.scop.desensitize.encry.rreversible.symmetry.AbstractSymmetryEncry;
import com.scop.desensitize.exception.strategy.DecodeException;
import com.scop.desensitize.exception.strategy.EncodeException;
import com.scop.desensitize.strategy.rreversible.symmetry.NumStrategy;
import org.apache.log4j.Logger;

import java.security.NoSuchAlgorithmException;

public class NumStrategyDemo {

    public static Logger log = Logger.getLogger(NumStrategyDemo.class);
    public static void main(String[] args) throws EncodeException, DecodeException {
        String password = "66";
        String data = "123";
        /**
         * @desc  自定义密码加密
         */
        customEncry(password,data);
        /**
         * @desc 默认加密
         */
//        defaultEncry(data);
    }

    /**
     * @desc 密码
     */
    public static void customEncry(String password,String data) throws EncodeException, DecodeException {
        AbstractSymmetryEncry num= NumStrategy.getInstance();
        String encodeNum =(String) num.encode(password,data);
        String decodeNum =(String) num.decode(password,encodeNum);

        log.info("默认数据："+data);
        log.info("加密数据："+encodeNum);
        log.info("解密数据："+decodeNum);
    }

    /**
     * @desc 默认执行
     * @throws NoSuchAlgorithmException
     */
    public static void defaultEncry(String str) throws EncodeException, DecodeException {
        AbstractSymmetryEncry num= NumStrategy.getInstance();
        String encodeStr =(String) num.encode(str);
        String decodeStr =(String) num.decode(encodeStr);

        log.info("默认数据："+str);
        log.info("加密数据："+encodeStr);
        log.info("解密数据："+decodeStr);
    }

}
